package love.unknown.fruit.dao.impl;

import love.unknown.fruit.dao.FruitDao;
import love.unknown.fruit.dao.base.BaseDAO;
import love.unknown.fruit.pojo.Fruit;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class FruitDAOImpl extends BaseDAO<Fruit> implements FruitDao {

    @Override
    public List<Fruit> getFruitList() {

        return super.excuteQuery("select * from t_fruit");
    }

    @Override
    public boolean addFruit(Fruit fruit) {
        String sql = "insert into t_fruit values(0,?,?,?,?)";
        int count =  super.executeUpdate(sql,fruit.getFname(), fruit.getPrice(), fruit.getFcount(), fruit.getRemark()) ;
        System.out.println(count);
        return count>0;
    }

    @Override
    public boolean updateFruit(Fruit fruit) {
        String sql = "update t_fruit set fcount = ? where fid = ?";
        return super.executeUpdate(sql, fruit.getFcount(), fruit.getFid()) > 0;
    }

    @Override
    public Fruit getFruitByName(String fname) {
        return super.load("select * from t_fruit where fname like ?",fname);
    }

    @Override
    public boolean delFruit(String fname) {
        String sql = "delete from t_fruit where fname like ?";
        return super.executeUpdate(sql, fname) > 0;
    }
}
